/*
 * ACC_Interface.c
 *
 * Created: 3/17/2012 1:42:58 PM
 *  Author: Unithra.C
 */ 
#include <avr/io.h>
#include "inc\TWI_Master.h"
#include "inc\ACC_Interface.h"
#include "inc\Uart.h"

unsigned char ReadByte(unsigned char Device_addr,unsigned char Reg_Addr)
{
	char RcvData =0;
	TWI_start();                                              // start twi
	TWI_write_address(Device_addr | WRITE);                              // 
	while(!(PINC && (1 << PC0)));                             // wait for SCL line to go high check for slave busy
	TWI_write_data(Reg_Addr);                                     // Read ctrl reg
	while(!(PINC && (1 << PC0)));                             // wait for SCL line to go high check for slave busy
	TWI_repeated_start();                                     // repeat start
	TWI_read_address(Device_addr | READ);                                // Read address
	while(!(PINC && (1 << PC0)));                             // wait for SCL line to go high check for slave busy
	RcvData = TWDR;
	TWI_stop();
	return RcvData;
}